package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocEndowmentInsurancegrantDao;
import com.irdstudio.cdp.pboc.service.domain.PbocEndowmentInsurancegrant;
import com.irdstudio.cdp.pboc.service.facade.PbocEndowmentInsurancegrantService;
import com.irdstudio.cdp.pboc.service.vo.PbocEndowmentInsurancegrantVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 养老保险金发放记录				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocEndowmentInsurancegrantService")
public class PbocEndowmentInsurancegrantServiceImpl implements PbocEndowmentInsurancegrantService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocEndowmentInsurancegrantServiceImpl.class);

	@Autowired
	private PbocEndowmentInsurancegrantDao pbocEndowmentInsurancegrantDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocEndowmentInsurancegrant(PbocEndowmentInsurancegrantVO inPbocEndowmentInsurancegrantVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocEndowmentInsurancegrantVo.toString());
		int num = 0;
		try {
			PbocEndowmentInsurancegrant pbocEndowmentInsurancegrant = new PbocEndowmentInsurancegrant();
			beanCopy(inPbocEndowmentInsurancegrantVo, pbocEndowmentInsurancegrant);
			num = pbocEndowmentInsurancegrantDao.insertPbocEndowmentInsurancegrant(pbocEndowmentInsurancegrant);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocEndowmentInsurancegrantVO inPbocEndowmentInsurancegrantVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocEndowmentInsurancegrantVo);
		int num = 0;
		try {
			PbocEndowmentInsurancegrant pbocEndowmentInsurancegrant = new PbocEndowmentInsurancegrant();
			beanCopy(inPbocEndowmentInsurancegrantVo, pbocEndowmentInsurancegrant);
			num = pbocEndowmentInsurancegrantDao.deleteByPk(pbocEndowmentInsurancegrant);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocEndowmentInsurancegrantVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocEndowmentInsurancegrantVO inPbocEndowmentInsurancegrantVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocEndowmentInsurancegrantVo.toString());
		int num = 0;
		try {
			PbocEndowmentInsurancegrant pbocEndowmentInsurancegrant = new PbocEndowmentInsurancegrant();
			beanCopy(inPbocEndowmentInsurancegrantVo, pbocEndowmentInsurancegrant);
			num = pbocEndowmentInsurancegrantDao.updateByPk(pbocEndowmentInsurancegrant);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocEndowmentInsurancegrantVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocEndowmentInsurancegrantVO queryByPk(PbocEndowmentInsurancegrantVO inPbocEndowmentInsurancegrantVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocEndowmentInsurancegrantVo);
		try {
			PbocEndowmentInsurancegrant queryPbocEndowmentInsurancegrant = new PbocEndowmentInsurancegrant();
			beanCopy(inPbocEndowmentInsurancegrantVo, queryPbocEndowmentInsurancegrant);
			PbocEndowmentInsurancegrant queryRslPbocEndowmentInsurancegrant = pbocEndowmentInsurancegrantDao.queryByPk(queryPbocEndowmentInsurancegrant);
			if (Objects.nonNull(queryRslPbocEndowmentInsurancegrant)) {
				PbocEndowmentInsurancegrantVO outPbocEndowmentInsurancegrantVo = beanCopy(queryRslPbocEndowmentInsurancegrant, new PbocEndowmentInsurancegrantVO());
				logger.debug("当前查询结果为:"+ outPbocEndowmentInsurancegrantVo.toString());
				return outPbocEndowmentInsurancegrantVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocEndowmentInsurancegrantVO> queryAllOwner(PbocEndowmentInsurancegrantVO pbocEndowmentInsurancegrantVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocEndowmentInsurancegrantVO> list = null;
		try {
			List<PbocEndowmentInsurancegrant> pbocEndowmentInsurancegrants = pbocEndowmentInsurancegrantDao.queryAllOwnerByPage(pbocEndowmentInsurancegrantVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocEndowmentInsurancegrants.size());
			pageSet(pbocEndowmentInsurancegrants, pbocEndowmentInsurancegrantVo);
			list = (List<PbocEndowmentInsurancegrantVO>) beansCopy(pbocEndowmentInsurancegrants, PbocEndowmentInsurancegrantVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocEndowmentInsurancegrantVO> queryAllCurrOrg(PbocEndowmentInsurancegrantVO pbocEndowmentInsurancegrantVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocEndowmentInsurancegrant> pbocEndowmentInsurancegrants = pbocEndowmentInsurancegrantDao.queryAllCurrOrgByPage(pbocEndowmentInsurancegrantVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocEndowmentInsurancegrants.size());
		List<PbocEndowmentInsurancegrantVO> list = null;
		try {
			pageSet(pbocEndowmentInsurancegrants, pbocEndowmentInsurancegrantVo);
			list = (List<PbocEndowmentInsurancegrantVO>) beansCopy(pbocEndowmentInsurancegrants, PbocEndowmentInsurancegrantVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocEndowmentInsurancegrantVO> queryAllCurrDownOrg(PbocEndowmentInsurancegrantVO pbocEndowmentInsurancegrantVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocEndowmentInsurancegrant> pbocEndowmentInsurancegrants = pbocEndowmentInsurancegrantDao.queryAllCurrDownOrgByPage(pbocEndowmentInsurancegrantVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocEndowmentInsurancegrants.size());
		List<PbocEndowmentInsurancegrantVO> list = null;
		try {
			pageSet(pbocEndowmentInsurancegrants, pbocEndowmentInsurancegrantVo);
			list = (List<PbocEndowmentInsurancegrantVO>) beansCopy(pbocEndowmentInsurancegrants, PbocEndowmentInsurancegrantVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}

	/**
	 * 需求编号:2019D0519
	 * 问题编号:
	 * 开发人员: caoxin
	 * 创建日期:2019/7/19
	 * 功能描述:通过reportId查询养老金发放记录
	 * 修改日期:2019/7/19
	 * 修改描述:
	 */
//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:通过reportId查询养老金发放记录
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响实际业务
//	public List<PbocEndowmentInsurancegrantVO> queryByReportId(PbocEndowmentInsurancegrantVO inPbocEndowmentInsurancegrantVo) throws Exception {
//
//		logger.debug("当前查询参数信息为:");
//
//		List<PbocEndowmentInsurancegrantVO> list = null;
//		try {
//			PbocEndowmentInsurancegrant pbocEndowmentInsurancegrant = new PbocEndowmentInsurancegrant();
//			beanCopy(inPbocEndowmentInsurancegrantVo, pbocEndowmentInsurancegrant);
//			List<PbocEndowmentInsurancegrant> pbocEndowmentInsurancegrants = pbocEndowmentInsurancegrantDao.queryByReportId(pbocEndowmentInsurancegrant);
//			logger.debug("当前查询结果为:"+ pbocEndowmentInsurancegrants.size());
//			list = (List<PbocEndowmentInsurancegrantVO>) beansCopy(pbocEndowmentInsurancegrants, PbocEndowmentInsurancegrantVO.class);
//		} catch (Exception e) {
//			logger.error("数据转换出现异常!", e);
//			throw e;
//		}
//
//		return list;
//	}
}
